package com.ruoyi.app.controller.shop.controller;

import com.ruoyi.app.controller.shop.service.IShopService;
import com.ruoyi.app.framework.base.BaseAppController;
import com.ruoyi.common.annotation.ParseShopId;
import com.ruoyi.common.annotation.PassToken;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.entity.VO.shop.ShopSearchVO;
import com.ruoyi.common.entity.VO.shop.ShopVO;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.StringUtils;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

/**
 * 站点管理
 */
@RestController
@RequestMapping("api/shop")
public class ShopController extends BaseAppController {

    @Resource
    private IShopService shopService;

    /**
     * 获取站点信息
     */
    @PassToken
    @GetMapping("/detail")
    public AjaxResult detail(@ApiIgnore @ParseShopId Long shopId) {
        ShopSearchVO shopSearchVO = new ShopSearchVO();
        if (StringUtils.isNotEmpty(ServletUtils.getParameter("lat"))) {
            shopSearchVO.setLat(Double.valueOf(ServletUtils.getParameter("lat")));
        }
        if (StringUtils.isNotEmpty(ServletUtils.getParameter("lon"))) {
            shopSearchVO.setLon(Double.valueOf(ServletUtils.getParameter("lon")));
        }
        shopSearchVO.setShopId(shopId);
        ShopVO shopInfo = shopService.getShopGeneralInfo(shopSearchVO);
        if (shopInfo != null) {
            return AjaxResult.success(shopInfo);
        } else {
            return error("沒有找到该油站信息！");
        }
    }
}
